import Taro, { Component } from '@tarojs/taro'
import { View } from '@tarojs/components'
import './index.scss'
import { APP_SYSTEM_INFO } from '@/config/config'
import { toHomePage } from "@/utils/page_router"

interface IProps {
  opacity: any
}

export default class NavbarHome extends Component<IProps, {}> {
  state: any
  props: any
  static options = {
    addGlobalClass: true
  }

  constructor() {
    super(...arguments)
    this.state = {}
  }

  //  返回上一页面
  onBack () {
    const pages = Taro.getCurrentPages()
    if (pages.length === 1) {
      toHomePage()
    } else {
      Taro.navigateBack()
    }
  }

  render() {
    const { opacity } = this.props
    const { capsule, navBarHeight } = APP_SYSTEM_INFO
    return (<View className='fy-popup fy-popup--top navbar-home' style={{ height: `${navBarHeight}px`, background: `rgba(255, 255, 255, ${opacity})` }}>
      <View className='custom-area' style={{ width: `${capsule.left}px`, height: `${capsule.height}px`, top: `${capsule.top}px`, opacity }}>
        {this.props.children}
      </View>
    </View>)
  }
}
